package tech.gismap.admin.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import tech.gismap.admin.domain.DaTableColumn;
import tech.gismap.admin.web.bo.DaTableColumnBo;
import tech.gismap.admin.web.vo.DaTableColumnVo;
import tech.gismap.admin.mapper.DaTableColumnMapper;
import tech.gismap.common.mybatis.core.page.PageQuery;
import tech.gismap.common.mybatis.core.page.TableDataInfo;

/**
* 数据集属性
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class DaTableColumnService {

    private final DaTableColumnMapper baseMapper;

    public TableDataInfo<DaTableColumnVo> selectPageList(DaTableColumnBo bo, PageQuery pageQuery) {
        Page<DaTableColumnVo> page = baseMapper.selectVoPage(pageQuery.build(), this.buildQueryWrapper(bo));
        return TableDataInfo.build(page);
    }

    private Wrapper<DaTableColumn> buildQueryWrapper(DaTableColumnBo bo) {
        LambdaQueryWrapper<DaTableColumn> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(bo.getId()!=null,DaTableColumn::getId,bo.getId());
        wrapper.eq(bo.getCreateBy()!=null,DaTableColumn::getCreateBy,bo.getCreateBy());
        wrapper.ge(bo.getBeginCreateTime()!=null,DaTableColumn::getCreateTime,bo.getBeginCreateTime());
        wrapper.lt(bo.getEndCreateTime()!=null,DaTableColumn::getCreateTime,bo.getEndCreateTime());
        wrapper.eq(bo.getUpdateBy()!=null,DaTableColumn::getUpdateBy,bo.getUpdateBy());
        wrapper.ge(bo.getBeginUpdateTime()!=null,DaTableColumn::getUpdateTime,bo.getBeginUpdateTime());
        wrapper.lt(bo.getEndUpdateTime()!=null,DaTableColumn::getUpdateTime,bo.getEndUpdateTime());
        wrapper.eq(bo.getCreateDept()!=null,DaTableColumn::getCreateDept,bo.getCreateDept());
        wrapper.orderByDesc(DaTableColumn::getUpdateTime);
        return wrapper;
    }
}
